package mytest;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springside.modules.utils.spring.SpringContextHolder;

import com.storeapp.dao.DealOrderDao;
import com.storeapp.dao.MyCustomerDao;
import com.storeapp.entity.domain.DealOrder;
import com.storeapp.entity.domain.Item;
import com.storeapp.entity.domain.MyCustomer;
import com.storeapp.service.DealOrderService;
import com.storeapp.service.MycustomerService;

public class TestApp {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Date date = new Date();
		System.out.println(String.format("%1$tY-%1$tm-%1$te", date));

		Pattern p = Pattern.compile("[^0-9.]");
		String s = "￥6,6666.77777";
		Matcher m = p.matcher(s);
		s = m.replaceAll("");
		System.out.print(s);

		// ApplicationContext ctx = new FileSystemXmlApplicationContext(
		// "/resources/applicationContext.xml");
		// DealOrderService orderService = (DealOrderService)
		// ctx.getBean("dealOrderService");
		// List<Item> items = new ArrayList<Item>();
		// for (int i = 1; i < 10; i++) {
		// items.add(new Item("item" + i, "provider" + i, i + " year",
		// (100 - i*10.00) / 100, i , i*10.00) );
		// }
		// orderService.saveDealOrder(3L, items);
		/*
		 * fetch
		 */
		// DealOrderDao orderDao = new DealOrderDao();
		// DealOrderService orderService = (DealOrderService)
		// ctx.getBean("dealOrderService");
		// List<DealOrder> orderList = orderService.listAll();
		// DealOrder order = orderList.get(0);
		// String i = orderService.listItemsByOrder(order).toString();
		// System.out.println(i);
		/*
		 * operate on service
		 */
		// MycustomerService service = (MycustomerService)
		// ctx.getBean("mycustomerService");
		// MyCustomer entity = new MyCustomer("我是天才", new Date(), "1111", "M");
		// service.saveOrUpdateMycustomer(entity);
		/*
		 * using Generic DAO implement
		 */
		// MyCustomerDao mycustomerDao = ctx.getBean(MyCustomerDao.class);
		// //HibernateUtils.
		// MyCustomer c = new MyCustomer("我是天才", new Date(), "1111", "M");
		// mycustomerDao.save(c);

		/*
		 * Straightforward use session factory
		 */
		// Session session = sessionfactory.openSession();
		//
		// // SessionFactory sessionFactory = new
		// AnnotationConfiguration().configure().buildSessionFactory();
		// // Session session = sessionFactory.getCurrentSession();
		//
		// if (session != null) {
		// session.beginTransaction();
		// MyCustomer c = new MyCustomer("我是天才", new Date(), "1111", "M");
		// session.save(c);
		// session.getTransaction().commit();
		// }
	}

}
